package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToAuthBOConverter;
import com.ssy.lingxi.member.merchant.model.bo.AuthBO;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 下级会员的权限
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-13
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_relation_auth", indexes = {@Index(name="ms_mc_member_relation_auth_relation_id_idx", columnList = "relation_id")})
public class MemberRelationAuthDO implements Serializable {
    private static final long serialVersionUID = -9201478858382231445L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_relation_auth_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_relation_auth_seq", name="member_relation_auth_seq",allocationSize = 1)
    private Long id;

    /**
     * 一对一双向关联会员关系
     */
    @JsonBackReference
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="relation_id", referencedColumnName="id")
    private MemberRelationDO relation;

    /**
     * 由于审核的时候可以修改权限，所以这里要保存一份，默认来自关联的角色的权限
     */
    @Convert(converter = JpaJsonToAuthBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<AuthBO> auth;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public MemberRelationDO getRelation() {
        return relation;
    }

    public void setRelation(MemberRelationDO relation) {
        this.relation = relation;
    }

    public List<AuthBO> getAuth() {
        return auth;
    }

    public void setAuth(List<AuthBO> auth) {
        this.auth = auth;
    }
}
